package com.example.webchar.webchar.service.serverimpl;

import com.example.webchar.webchar.mapper.slave.ChapterNameSlave;
import com.example.webchar.webchar.mapper.slave.NovelContentSlave;
import com.example.webchar.webchar.pojo.ChapterName;
import com.example.webchar.webchar.pojo.NovelContent;
import com.example.webchar.webchar.service.NovelContentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @program: webchars
 * @description
 * @author: YouName
 * @create: 2021-08-28 09:04
 **/
@Component
public class NovleContenServImpl implements NovelContentService {
    @Autowired
    private NovelContentSlave novelContentSlave;
    @Autowired
    private ChapterNameSlave chapterNameSlave;


    @Override
    public List<ChapterName> quereyNovelContenofChapteNameIdService(Integer chapteNameId) {
        List<ChapterName> chapterNames = chapterNameSlave.querChapterNameById(chapteNameId);
        List<NovelContent> novelContents = novelContentSlave.queryContentByChapterList(chapterNames);
        for (ChapterName chapterName : chapterNames) {
            for (NovelContent novelContent : novelContents) {
                if (chapterName.getId().equals(novelContent.getChapterNameId())) {
                    chapterName.setNovelContent(novelContent);
                }
            }
        }
        return chapterNames;
    }
}
